//
//  LoginController.swift
//  iostest
//
//  Created by jin on 2024/8/1.
//

import UIKit

class LoginController: UIViewController {

    @IBOutlet weak var tipView: UILabel!
    @IBOutlet weak var phoneView: UITextField!
    @IBOutlet weak var passwordView: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
    

    @IBAction func clickLogin(_ sender: Any) {
        let phone = phoneView.text!
        if phone.isEmpty{
            tipView.text = "手机号不能为空"
            return
        }
        
        if !phone.isPhone(){
            tipView.text = "手机号格式不正确"
            return
        }
        
        let password = passwordView.text!
        if password.isEmpty{
            tipView.text = "密码不能为空"
            return
        }
        
        if password.count < 6 || password.count > 15 {
            tipView.text = "密码格式不正确（6~15位）"
            return
        }
        
        ///请求接口，校验账号密码
        if Constant.PHONE == phone && Constant.PASSWORD == password{
            ///登录成功
            PreferenceUtil.setLogin(true)
            SceneDelegate.shared.toHome()
        }else{
            tipView.text = "手机号或密码错误"
        }
        
    }

}
